/**
  ETFAna project, Anyang Normal University && IMP-CAS
  \brief calculate the thickness of the laser ball pat
  \note intended for internal use (meant for the developers) only
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2023-12-12
  \date 2023-12-12 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2023-12-12   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2021-2024 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#include <string>
#include <iostream>
#include "ETFMath.h"
#include "ETFYaml.h"

using std::string;
using std::cout;
using std::endl;

// static const string posconfig = "../etfana/config/apr2023/doc/pos.yaml";
static const string posconfig = "pos.yaml";

int main(){
  // calculate distance of 2 parallel planes - Dec.11, 2023 //
  // no pat
  const double a0[3] = {240.90, 392.66, 2004.56};
  const double b0[3] = {1199.16, 362.37, 1745.14};
  const double c0[3] = {240.13, -236.55, 1998.47};
  const double d0[3] = {1200.32, -100.76, 1743.20};
  // // with pat
  const double a1[3] = {377.46, 386.87, 1963.06};
  const double b1[3] = {1060.07, 390.36, 1778.10};
  const double c1[3] = {380.18, -362.28, 1956.28};
  const double d1[3] = {1063.58, -359.08, 1773.88};
  static const double DPAT = 25.; //

  // ETF-25.4-Oct.30
  // no pat
  // const double a0[3] = {833.15, 159.33, 5044.57};
  // const double b0[3] = {837.36,  48.07, 5039.87};
  // const double c0[3] = {1790.13, 353.15, 4789.92};
  // const double d0[3] = {1793.48, -7.94, 4788.95};
  // with pat
  // const double a1[3] = {968.19, 383.19, 5005.84};
  // const double b1[3] = {1651.12, 388.05, 4824.11};
  // const double c1[3] = {971.12, -367.34, 4998.32};
  // const double d1[3] = {1655.17, -361.33, 4817.24};
  // static const double DPAT = 25.4; //

  // const double a0[3] = {1., 0., 0.};
  // const double b0[3] = {0., 1., 0.};
  // const double c0[3] = {0., 0., 1.};
  // const double a1[3] = {2., 0., 0.};
  // const double b1[3] = {0., 2., 0.};
  // const double c1[3] = {0., 0., 2.};

  double dd = 0., dd1 = 0.;
  double n0[3]{}, n1[3]{}; // the normal vector
  ETFMath::Plane(n0, a0, b0, c0);
  ETFMath::Plane(n1, a1, b1, c1);
  dd = ETFMath::PlaneDistance(n0, n1) + DPAT;
  dd1 += dd;
  cout << "dd0: " << dd << "mm" << endl;
  ETFMath::Plane(n0, a0, b0, d0);
  ETFMath::Plane(n1, a1, b1, d1);
  dd = ETFMath::PlaneDistance(n0, n1) + DPAT;
  dd1 += dd;
  cout << "dd1: " << dd << "mm" << endl;
  ETFMath::Plane(n0, a0, c0, d0);
  ETFMath::Plane(n1, a1, c1, d1);
  dd = ETFMath::PlaneDistance(n0, n1) + DPAT;
  dd1 += dd;
  cout << "dd2: " << dd << "mm" << endl;
  ETFMath::Plane(n0, b0, c0, d0);
  ETFMath::Plane(n1, b1, c1, d1);
  dd = ETFMath::PlaneDistance(n0, n1) + DPAT;
  dd1 += dd;
  cout << "dd3: " << dd << "mm" << endl;
  dd1 /= 4.;
  cout << "distance: \033[1m" << dd1 << "\033[0mmm" << endl;

  return 0;
} // end main function
